package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author fenge
 */
@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierDao supplierDao;


    @Override
    public Map<String, Object> list(Integer page, Integer rows, String supplierName) {
        Map<String, Object> map = new HashMap<>();
        Integer offset = (page-1) * (rows);
        List<Supplier> list = supplierDao.getlist(offset,rows,supplierName);
        Long total = supplierDao.getTotal();
        map.put("total",total);
        map.put("rows",list);

        return map;
    }

    @Override
    public void save(Supplier supplier) {
        if (supplier.getSupplierId()==null) {
            supplierDao.save(supplier);
        }
        supplierDao.updateById(supplier);
    }

    @Override
    public void delete(String ids) {
        supplierDao.delete(ids);
    }

    @Override
    public List<Supplier> getComboboxList(String q) {
        return supplierDao.getlist(0,99,q);
    }
}
